/*
 * @Descripttion: 文件说明
 * @version: 0.0.1
 * @Author: zhangmeng
 * @Date: 2022-10-09 15:55:09
 * @LastEditors: zhangmeng
 * @LastEditTime: 2022-10-18 09:14:19
 */
import Vue from 'vue';

const basicsList = require.context('./basics', true, /.vue$/); //获取基础素材文件
const complexList = require.context('./complex', true, /.vue$/); //获取高级素材文件

const GetBasicsList = () => {
    let list = [];
    basicsList.keys().forEach(fileName => {
        const component = basicsList(fileName).default; // 基础组件
        const componentName = component.pageData.name;
        const hidden = component.pageData.hidden;
        if (componentName) Vue.component(componentName, component);
        if (!hidden) list.push(component.pageData);
    });

    list = list.sort(function(a, b) {
        return a.sort - b.sort;
    });
    return list;
};


const GetComplexList = () => {
    let list = [];
    complexList.keys().forEach(fileName => {
        const component = complexList(fileName).default; // 高级组件
        const componentName = component.pageData.name;
        if (componentName) Vue.component(componentName, component);
        list.push(component.pageData);
    });

    list = list.sort(function(a, b) {
        return a.sort - b.sort;
    });
    return list;
};

const ComplexList = () => {
    let list = [{
        title: '基础组件',
        name: 'basics',
        show: true,
        complex: GetBasicsList()
    }, {
        title: '高级组件',
        name: 'basics',
        show: true,
        complex: GetComplexList()
    }]
    return list;
}

export default ComplexList;